/*************************************************************
 * File: SpringObjectFactory.java
 * Copyright (c) 2012
 * Author: Huang Shaobin
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com 
 * Date: Mar 17, 2013
 * Description: 
 ************************************************************/

package snow.core.web.rest.restlet;

import org.restlet.ext.jaxrs.InstantiateException;
import org.restlet.ext.jaxrs.ObjectFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * TODO
 * 
 * @author Shaobin.Software@gmail.com Shaobin_Software@163.com
 * @version 1.0
 */
public class SpringObjectFactory implements ObjectFactory, BeanFactoryAware {

	private BeanFactory beanFactory;

	public BeanFactory getBeanFactory() {
		return this.beanFactory;
	}

	/**
	 * @param <T>
	 * @param jaxRsClass
	 * @return
	 * @throws InstantiateException
	 * @see org.restlet.ext.jaxrs.ObjectFactory#getInstance(java.lang.Class)
	 */
	public <T> T getInstance(Class<T> jaxRsClass) throws InstantiateException {
		return jaxRsClass == null ? null : beanFactory.getBean(jaxRsClass);
	}

	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}

}
